<template>  
    <div class="icons">
        <swiper ref="mySwiper" :options="swiperOption">
            <swiper-slide 
                v-for="page of pages"
                :key="page[0].id"
            >
                <div 
                    class="icon"
                    v-for="icon of page"
                    :key="icon.id"
                >
                    <div class="icon-img">
                        <img class="icon-img-content" :src="icon.imgUrl" alt="">
                    </div>
                    <p class="icon-desc">{{ icon.desc }}</p>
                </div>
            </swiper-slide>
        </swiper>
        {{pages }}
    </div>
</template>
<script>
export default {
    name:'HomeIcons',
    props:{
        list:Array
    },
    data(){
        return{
            iconList:[
                {
                    id:'001',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点'
                },{
                    id:'002',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点'
                },{
                    id:'003',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点'
                },{
                    id:'004',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'一日游'
                },{
                    id:'005',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点'
                },{
                    id:'006',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点'
                },{
                    id:'007',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点tttttgggg'
                },{
                    id:'008',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'热门景点'
                },{
                    id:'009',
                    imgUrl:'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
                    desc:'测试'
                }
            ],
            swiperOption:{
                autoflay:false
            }
        } 
    },
    computed:{
        pages(){
            const pages = [];
            this.list.forEach((ele,key) => {
                const page = Math.floor(key/8)
                if(!pages[page]){
                    pages[page] = []
                }
                 pages[page].push(ele)
            })
            return pages
        }
    },
}
</script>
<style lang="stylus" scoped>
    @import '~@/assets/styles/variables.styl'
    @import '~@/assets/styles/mixins.styl'
    .icons >>> .swiper-container
        height:0
        padding-bottom:50%
    .icons
        overflow hidden
        height:0
        padding-bottom:50%
        margin-top:.1rem
        .icon
            position:relative
            overflow hidden
            float:left
            width:25%
            height:0
            padding-bottom:25%
            .icon-img
                position:absolute
                top:0
                left:0
                right:0
                bottom:.44rem 
                box-sizing:border-box
                padding:.1rem  
                .icon-img-content
                    display:block
                    height:100%
                    margin:0 auto
            .icon-desc
                position:absolute
                left:0
                right:0
                bottom:0
                height:.44rem
                line-height:.44rem
                text-align:center
                color:$darkTextColor
                ellipsis()

                    

</style>